package edu.scau.mis.core.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

/**
 * WebSocket配置类
 */
@Configuration
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    @Bean
    /**
     * 注入一个ServerEndpointExporter
     */
    public ServerEndpointExporter serverEndpointExporter(){
        return new ServerEndpointExporter();
    }

//    @Override
//    /**
//     * 端点注册
//     */
//    public void registerStompEndpoints(StompEndpointRegistry registry){
//        registry.addEndpoint("/endpointMark") //注册端点并映射url
//                .setAllowedOrigins("*") //允许所有域名访问
//                .withSockJS(); //开启sockJS协议
//    }
//
//    @Override
//    /**
//     * 消息代理
//     */
//    public void configureMessageBroker(MessageBrokerRegistry registry){
//        registry.enableSimpleBroker("/mess"); // 服务端发给客户端前缀
//        registry.setApplicationDestinationPrefixes("/app"); //客户端发给服务端前缀
//    }

}
